﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Reflection;
using System.Collections.ObjectModel;
using System.ComponentModel;

namespace WPFColors
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public struct ColorType
        {
            public string Name { get; set; }
            public string Hex { get; set; }
        }

        public CollectionViewSource WPFColors { get; set; }

        public ObservableCollection<ColorType> myWPFColors { get; set; }

        public MainWindow()
        {
            myWPFColors = new ObservableCollection<ColorType>();

            WPFColors = new CollectionViewSource();
            WPFColors.Source = myWPFColors;
            WPFColors.SortDescriptions.Add(new SortDescription("Hex", ListSortDirection.Descending));

            Type t = typeof(System.Windows.Media.Brushes);
            
            PropertyInfo[] myBrushesColors = t.GetProperties();

            foreach (PropertyInfo myColor in myBrushesColors)
            {
                BrushConverter myBrushConverter = new BrushConverter();

                Brush myBrush = myBrushConverter.ConvertFrom(myColor.Name) as Brush;

                ColorType mycolorType = new ColorType();
                mycolorType.Name = myColor.Name;
                mycolorType.Hex = myBrush.ToString();

               myWPFColors.Add(mycolorType);
            }

            DataContext = WPFColors.View;

            InitializeComponent();
        }
    }
}
